import pandas as pd

series = pd.Series([165, 174, 160, 180, 159, 163, 192, 184],
                   index=['NO1: 165', 'NO2: 174', 'NO3: 160', 'NO4: 180', 'NO5: 159', 'NO6: 163', 'NO7: 192',
                          'NO8: 184'])

# 自动把数据分成3组
qcut = pd.qcut(series, 3)
print(qcut)

# 转换成one-hot编码
dummies = pd.get_dummies(qcut, prefix='height')
print(dummies)

# 自定义分组
bins = [150, 165, 180, 195]
cut = pd.cut(series, bins=bins)
# 查看分组中每组的个数
print(cut.value_counts())
print(cut)

# 转换成one-hot编码
cut_dummies = pd.get_dummies(cut, prefix='height')
print(cut_dummies)

